package chap02.LowArray;

/**
 * LowArray是数据结构，是一个工具，LowArrayApp是工具的使用者
 * Created by root on 2017/4/26.
 */
public class LowArrayApp {
    public static void main(String[] args) {
        LowArray arr;
        arr = new LowArray(100);
        int j;
        int nElems = 0;
        long searchKey;

        // insert 10 items
        arr.setElem(0,77);
        arr.setElem(1,99);
        arr.setElem(2,44);
        arr.setElem(3,55);
        arr.setElem(4,22);
        arr.setElem(5,88);
        arr.setElem(6,11);
        arr.setElem(7,00);
        arr.setElem(8,66);
        arr.setElem(9,33);
        nElems = 10;

        // display items
        for (j=0; j<nElems; j++) {
            System.out.print(arr.getElem(j) + " ");
        }
        System.out.println();

        // find item with key 66
        searchKey = 66;
        for (j=0; j<nElems; j++) {
            if (arr.getElem(j) == searchKey) {
                break;
            }
        }
        if (j == nElems) {
            System.out.println("can't find " + searchKey);
        } else {
            System.out.println("Found " + searchKey);
        }

        // delete item with key 55
        searchKey = 55;
        for (j=0; j<nElems; j++) {
            if (arr.getElem(j) == searchKey) {
                break;
            }
        }
        for (int k=j; k<nElems-1; k++) {
            arr.setElem(k, arr.getElem(k+1));
        }
        nElems--;

        // display items
        for (j=0; j<nElems; j++) {
            System.out.print(arr.getElem(j) + " ");
        }
        System.out.println();
    }

}
